﻿@model ProductControllerModel.Create
<div class="pageContent">
    <form method="post" action="/Product/Create?categoryCode=@Model.ProductCategoryCode" class="pageForm required-validate" onsubmit="return validateCallback(this, dialogAjaxDoneWithRefreshParentDialog);">
    <div class="pageFormContent">
        <div class="tabs">
            <div class="tabsHeader">
                <div class="tabsHeaderContent">
                    <ul>
                        <li><a href="javascript:void(0);"><span>信息</span></a></li>
                        @if (Model.ProductAttributeNames.Count(o => o.AttributeType != ProductAttributeType.Sale) > 0)
                        {
                            <li><a href="javascript:void(0);"><span>属性</span></a></li> 
                        }
                        <li><a href="javascript:void(0);"><span>销售属性</span></a></li>
                        <li><a href="javascript:void(0);"><span>描述</span></a></li>
                        <li><a href="javascript:void(0);"><span>包装清单</span></a></li>
                        <li><a href="javascript:void(0);"><span>售后服务</span></a></li>
                        <li><a href="javascript:void(0);"><span>图片</span></a></li>
                    </ul>
                </div>
            </div>
            <div class="tabsContent">
                <div>
                    <p>
                        <label>
                            名 称：
                        </label>
                        <input type="text" name="Name" />
                    </p>
                    <p>
                        <label>
                            SeName：
                        </label>
                        <input type="text" name="ProductExtra.SeName" />
                    </p>
                </div>
                @if (Model.ProductAttributeNames.Count(o => o.AttributeType != ProductAttributeType.Sale) > 0)
                {
                    <div>
                        @foreach (var pivotalAttr in Model.ProductAttributeNames.Where(o => o.AttributeType == ProductAttributeType.Pivotal))
                        {
                            var pivotalAttrTemp = pivotalAttr;
                            <p>
                                <label>
                                    @pivotalAttrTemp.AttributeName：
                                </label>
                                @if (pivotalAttrTemp.AttributeControlType == ProductAttributeControlType.DropDownList)
                                {
                                    <select name="attributes">
                                        @if (!pivotalAttrTemp.IsMust)
                                        {
                                            <option>请选择</option>
                                        }
                                        @foreach (var value in Model.ProductAttributeValues.Where(o => o.AttributeNameCode == pivotalAttrTemp.AttributeNameCode))
                                        {
                                            <option value="@(pivotalAttrTemp.AttributeNameCode):@(value.AttributeValueCode)" >@value.AttributeValueName</option>
                                        }
                                    </select>
                                }
                            </p>
                        }
                        @foreach (var normalAttr in Model.ProductAttributeNames.Where(o => o.AttributeType == ProductAttributeType.Normal))
                        {
                            var normalAttrTemp = normalAttr;
                            <p>
                                <label>
                                    @normalAttrTemp.AttributeName：
                                </label>
                                @if (normalAttrTemp.AttributeControlType == ProductAttributeControlType.DropDownList)
                                {
                                    <select name="attributes">
                                        @if (!normalAttr.IsMust)
                                        {
                                            <option>请选择</option>
                                        }
                                        @foreach (var value in Model.ProductAttributeValues.Where(o => o.AttributeNameCode == normalAttrTemp.AttributeNameCode))
                                        {
                                            <option value="@(normalAttr.AttributeNameCode):@(value.AttributeValueCode)" >@value.AttributeValueName</option>
                                        }
                                    </select>
                                }
                            </p>
                        }
                    </div>
                }
                <div>
                    @*<div>
                        @foreach (var saleAttr in Model.ProductAttributeNames.Where(o => o.AttributeType == ProductAttributeType.Sale))
                        {
                            var saleAttrTemp = saleAttr;
                            <p>
                                <label>
                                    @saleAttrTemp.AttributeName：
                                </label>
                                @if (saleAttrTemp.AttributeControlType == ProductAttributeControlType.CheckBox)
                                {
                                    foreach (var value in Model.ProductAttributeValues.Where(o => o.AttributeNameCode == saleAttrTemp.AttributeNameCode))
                                    {
                                    <input type="checkbox" name="attributes" value="@(saleAttrTemp.AttributeNameCode):@(value.AttributeValueCode)" />
                                    @value.AttributeValueName
                                    }
                                }
                            </p>
                        }</div>*@
                    @if (Model.ProductAttributeNames.Count(o => o.AttributeType == ProductAttributeType.Sale) > 0)
                    {
                        <div style="border: 1px solid #B8D0D6;">@GenerateSaleAttribute(Model.ProductAttributeNames, Model.ProductAttributeValues)
                        </div>
                    }
                    else
                    {
                        <div>
                            <p>
                                <label>
                                    价 格：
                                </label>
                                <input type="text" name="saleAttributes[0].price" class="digit" />
                            </p>
                            <p>
                                <label>
                                    库 存：
                                </label>
                                <input type="text" name="saleAttributes[0].quantity" class="digit" />
                                <input type="hidden" name="saleAttributes[0].code" value="@(Guid.NewGuid().ToString())" />
                                <input type="hidden" name="saleAttributes.Index" value="0" />
                            </p>
                        </div>
                    }
                </div>
                <div>
                    <textarea class="editor" name="ProductExtra.FullDescription" rows="8" cols="100"
                        uplinkurl="/Home/Upload/" uplinkext="zip,rar,txt" upimgurl="/Home/Upload/" upimgext="jpg,jpeg,gif,png"
                        upflashurl="/Home/Upload/" upflashext="swf" upmediaurl="/Home/Upload/" upmediaext="avi"
                        style="height: 350px;">
							</textarea></div>
                <div>
                    <textarea class="editor" name="ProductExtra.FullDescription" rows="8" cols="100"
                        uplinkurl="/Home/Upload/" uplinkext="zip,rar,txt" upimgurl="/Home/Upload/" upimgext="jpg,jpeg,gif,png"
                        upflashurl="/Home/Upload/" upflashext="swf" upmediaurl="/Home/Upload/" upmediaext="avi"
                        style="height: 350px;">
							</textarea></div>
                <div>
                    <textarea class="editor" name="ProductExtra.FullDescription" rows="8" cols="100"
                        uplinkurl="/Home/Upload/" uplinkext="zip,rar,txt" upimgurl="/Home/Upload/" upimgext="jpg,jpeg,gif,png"
                        upflashurl="/Home/Upload/" upflashext="swf" upmediaurl="/Home/Upload/" upmediaext="avi"
                        style="height: 350px;">
							</textarea></div>
                <div>
                    <div style="height: 35px;">
                        <input type="file" id="uploadify" name="fileUpload" uploader="/uploadify/scripts/uploadify.swf"
                            cancelimg="/uploadify/cancel.png" filequeue="fileQueue" script="/Home/UploadPicture/"
                            onallcomplete="uploadifyAllComplete" oncomplete="oncomplete" auto='true' />
                    </div>
                    <div class="divider">
                    </div>
                    <div id="fileQueue" class="fileQueue">
                    </div>
                    <div class="divider">
                    </div>
                    <div>
                        <ul id="pic-container" class="clearfix">
                        </ul>
                    </div>
                </div>
            </div>
            <div class="tabsFooter">
                <div class="tabsFooterContent">
                </div>
            </div>
        </div>
    </div>
    <div class="formBar">
        <ul>
            <li>
                <div class="buttonActive">
                    <div class="buttonContent">
                        <button type="submit">
                            保存</button></div>
                </div>
            </li>
            <li>
                <div class="button">
                    <div class="buttonContent">
                        <button type="button" class="close">
                            取消</button></div>
                </div>
            </li>
        </ul>
    </div>
    </form>
</div>
@helper GenerateSaleAttribute(IList<ProductAttributeName> names, IList<ProductAttributeValue> values)
    {
        var saleNames = names.Where(o => o.AttributeType == ProductAttributeType.Sale).ToList();
    <table class="table" width="100%" layouth="138">
        <thead>
            <tr>
                @foreach (var name in saleNames)
                {
                    var tempName = name;
                    <th align="center">
                        @tempName.AttributeName
                    </th>
                }
                <th width="200">
                    价格*
                </th>
                <th width="200">
                    数量*
                </th>
                <th width="200">
                </th>
            </tr>
        </thead>
        <tbody>
            @if (saleNames.Count == 1)
            {
                foreach (var value in Model.ProductAttributeValues.Where(o => o.AttributeNameCode == saleNames[0].AttributeNameCode))
                {
                    var index = value.AttributeNameCode + ":" + value.AttributeValueCode;

                <tr>
                    <td>@value.AttributeValueName
                    </td>
                    <td>
                        <input type="text" name="saleAttributes[@index].price" style="margin: 2px;" />
                    </td>
                    <td>
                        <input type="text" name="saleAttributes[@index].quantity" style="margin: 2px;" />
                    </td>
                    <td>
                        <input type="hidden" name="saleAttributes[@index].code" value="@(index)"  />
                        <input type="hidden" name="saleAttributes.Index" value="@(index)" />
                    </td>
                </tr>
                }
            }
            @if (saleNames.Count == 2)
            {
                foreach (var value in Model.ProductAttributeValues.Where(o => o.AttributeNameCode == saleNames[0].AttributeNameCode))
                {
                    var next = Model.ProductAttributeValues.Where(o => o.AttributeNameCode == saleNames[1].AttributeNameCode).ToList();
                    if (next.Any())
                    {
                        var index = value.AttributeNameCode + ":" + value.AttributeValueCode + "-" + next[0].AttributeNameCode + ":" + next[0].AttributeValueCode;
                <tr>
                    <td rowspan="@next.Count">@value.AttributeValueName
                    </td>
                    <td>@next[0].AttributeValueName
                    </td>
                    <td>
                        <input type="text" name="saleAttributes[@(index)].price" style="margin: 2px; height: 11px;" />
                    </td>
                    <td>
                        <input type="text" name="saleAttributes[@(index)].quantity" style="margin: 2px; height: 11px;" />
                    </td>
                    <td>
                        <input type="hidden" name="saleAttributes[@(index)].code" value="@(index)" />
                        <input type="hidden" name="saleAttributes.Index" value="@(index)" />
                    </td>
                </tr>
                        for (var i = 0; i < next.Count - 1; i++)
                        {
                            var x = next[i + 1];
                            var y = value.AttributeNameCode + ":" + value.AttributeValueCode + "-" + x.AttributeNameCode + ":" + x.AttributeValueCode;

                <tr>
                    <td>@x.AttributeValueName
                    </td>
                    <td>
                        <input type="text" name="saleAttributes[@(y)].quantity" style="margin: 2px; height: 11px;" />
                    </td>
                    <td>
                        <input type="text" name="saleAttributes[@(y)].price" style="margin: 2px; height: 11px;" />
                    </td>
                    <td>
                        <input type="hidden" name="saleAttributes[@(y)].code" value="@(y)" />
                        <input type="hidden" name="saleAttributes.Index" value="@(y)" />
                    </td>
                </tr>
                        }
                    }
                }
            }
        </tbody>
    </table>
}
